/**
 * 
 */
package gahCMP;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.zip.ZipInputStream;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;

/**
 * @author Administrator
 *
 */
public class ActivitiTest01 {
    /** 
     * 生成25张Activiti表 
     */  
    @Test
    public void testCreateTable() {  
        // 引擎配置  
        ProcessEngineConfiguration pec=ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();  
        pec.setJdbcDriver("oracle.jdbc.driver.OracleDriver");  
//        pec.setJdbcUrl("jdbc:oracle:thin:@192.168.0.28/orcl");  
        pec.setJdbcUrl("jdbc:oracle:thin:@127.0.0.1/xe"); 
        pec.setJdbcUsername("dzzw");  
        pec.setJdbcPassword("dzzw");  
        
//        pec.setJdbcDriver("com.mysql.jdbc.Driver");  
//        pec.setJdbcUrl("jdbc:mysql://localhost:3306/dzzw?useUnicode=true&characterEncoding=UTF8");  
//        pec.setJdbcUsername("root");  
//        pec.setJdbcPassword("123456"); 
           
        /** 
         * DB_SCHEMA_UPDATE_FALSE 不能自动创建表，需要表存在 
         * create-drop 先删除表再创建表 
         * DB_SCHEMA_UPDATE_TRUE 如何表不存在，自动创建和更新表   
         */  
        pec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);  
           
        // 获取流程引擎对象  
        ProcessEngine processEngine=pec.buildProcessEngine();  
        
        System.out.println(processEngine);
    }  
    

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    
    /** 
     * 部署流程定义使用zip方式 
     * @throws FileNotFoundException 
     */  
    @Test  
    public void deployWithZip() throws FileNotFoundException{ 
    	
    	String projectPath = System.getProperty("user.dir");
    	
    	String zipFilePaht = projectPath + "/src/main/webapp/backstage/declareflow/deploy/bpmn/level01nocheck.zip";
    	System.out.println(zipFilePaht);
        //  
        File file = new File(zipFilePaht);  
        FileInputStream in = new FileInputStream(file);  
        
//        InputStream in = this.getClass().getClassLoader().getResourceAsStream();  
        ZipInputStream zipInputStream = new ZipInputStream(in);  
        Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service  
                        .createDeployment()//创建部署对象                   
                        .name("一级审批流程（无监督检查）")
                        .addZipInputStream(zipInputStream)//使用zip方式部署，将helloworld.bpmn和helloworld.png压缩成zip格式的文件  
                        .deploy();//完成部署  
        System.out.println("部署ID："+deployment.getId());//1  
        System.out.println("部署时间："+deployment.getDeploymentTime());
    }  
    
}
